package com.accesshollywood.grfxOrdering.panels;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.EnumSet;

import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import com.accesshollywood.components.BasicPopupMenu;
import com.accesshollywood.components.EditableListWithPopup;
import com.accesshollywood.components.EditableListWithPopup.EditableListModel;
import com.accesshollywood.indexables.GrfxOrder;
import com.accesshollywood.indexables.items.TextIndexed;
import com.accesshollywood.prefs.Prefs;

public class NotesPanel extends JPanel {
	private GrfxOrder				grfxOrder;
	JComponent						parent;
	//public EditableOneColumnTable	notesTable;
	public EditableListWithPopup	notesTable;

	public NotesPanel(GrfxOrder model, JComponent parent) {
		super();
		grfxOrder = model;
		this.parent = parent;
	}

	public void createPanel(TextIndexed text) {
		setBorder(new TitledBorder(new LineBorder(Color.BLACK, 1), "Notes"));

		setAlignmentX(Component.LEFT_ALIGNMENT);
		setAlignmentY(Component.TOP_ALIGNMENT);
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

		//notesTable = new EditableOneColumnTable(this, "gfxOrder", "notes", "idOrder", Prefs.PixelSize.notes.get(), false);
		notesTable = new EditableListWithPopup(Prefs.PixelSize.notes.get(), TextIndexed.class);

		if (grfxOrder != null) {
			((EditableListModel)notesTable.getModel()).create(text, grfxOrder.getAssignedUsers());
		}
/*
		notesTable.setTableHeader(null);

		notesTable.setFillsViewportHeight(true);
		notesTable.setShowGrid(false);
		notesTable.setShowHorizontalLines(false);
		notesTable.setShowVerticalLines(false);
		*/
		notesTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

		setupPopup();

		int h = 2 * (notesTable.getModel().getSize() + 1);// * notesTable.getRowHeight();

		JScrollPane scrollPane = new JScrollPane(notesTable);
		scrollPane.setPreferredSize(new Dimension(275, h));
		scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);

		add(scrollPane);
	}

	public void setupPopup() {
		notesTable.popup.popupItems = EnumSet.of(
				BasicPopupMenu.POPUP_ITEMS.EDIT
				);
		notesTable.setupPopup();
	}
}
